package com.oocl.homework.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.homework.pojo.Areas;
import com.oocl.homework.service.getAreas;
import com.oocl.homework.service.impl.getAreasImpl;
import com.oocl.homework.util.RequestUtil;

/**
 * Servlet implementation class GetAreasServlet
 */
public class GetAreasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private getAreas getAreas;
       

    public GetAreasServlet() {
        super();
        getAreas=new getAreasImpl();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String area=request.getParameter("area");
		System.out.println(area);
		List<Areas> list=new ArrayList<Areas>();
		list=getAreas.getAreas(area);
		System.out.println(list.size());
		response.setContentType("application/json; charset=utf-8"); 				
		response.setHeader("Access-Control-Allow-Origin", "*");
						
		response.getWriter().write(RequestUtil.wrapToJson(list));
				

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
